const Monitor = require('../../utils/monitor.js').Monitor
const util = require('../../utils/util.js')
Page(Monitor.hookApp({
  data: {
    imgUrl: getApp().globalData.imgUrl,
    imgUrls: getApp().globalData.imgUrls,
   phoneBeifei:'wm6wf6fg5g4h电话备份.svg',
    fuZhi:'wmas25f4hg5复制备份.svg',
    duiHao:'wmghas554s8js.svg',
    huiSe:'wmawdsa216sdg4灰色人头像.svg',
    shouHuo:'wmsd54g5a85收(1).svg',
    yunSunZhong:'wm2s5g1dse运输中备份.svg',
  },
  onLoad: function (options) {
    console.log(options)
    this.setData({
      order_id: options.order_id
    })
  },
  onShow(){
    this.getLogistics(this.data.order_id)
  },
  tel: function (e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone,
    })
  },
  goOrder(){
    wx.navigateTo({
      url: `/pages/DingDanXiangYiWanChengSJPS/DingDanXiangYiWanChengSJPS?order_id=${this.data.order_id}&distributiontype=${this.data.distributiontype}`,
    })
  },
  getLogistics(order_id){   //获取物流信息
    util.API('pyapi/kdi',{
      order_id: parseInt(order_id)
    }, 'application/x-www-form-urlencoded').then(res=>{
      if (res.data.status == 0 ){   //快递单号查询成功

        let list = res.data.result.list  
        // 更改返回数据的日期格式
        list.map((val)=>{
          let arr = val.time.split(' ')
          let dateStr = arr[0]
          let dateArr = dateStr.split('-')
          arr[0] = [dateArr[1], dateArr[2]]
          val.date = arr[0]
          val.time = arr[1]
          return val
        })

        this.setData({
          distributiontype: res.distributiontype,
          address_info: res.address_info,
          result: res.data.result
        })

        console.log(this.data.result)

      }else{  // 快递单号查询失败
        wx.showToast({
          title: res.data.msg,
          icon:'none'
        })
      }
      this.setData({
        goods_list: res.goods_list
      })
    })
  },

  copy(e){
   
    wx.setClipboardData({
      data: e.currentTarget.dataset.copy,
      success(res) {
        wx.getClipboardData({
          success(res) {
            console.log(res.data) // data
          }
        })
      }
    })
  }
}))